package com.example.piece.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.example.base.ext.setCircleCropImageUrl
import com.example.piece.R
import com.example.piece.BR

import com.example.piece.databinding.ItemHomeFollowBinding
import com.example.piece.entity.RecommendEntity

class HomeFollowAdapter(data: List<RecommendEntity>) :
    BaseQuickAdapter<RecommendEntity, BaseDataBindingHolder<ItemHomeFollowBinding>>(
        R.layout.item_home_follow
    ) {


    /*   */
    /**  点击item  **/
    /*@RepeatClick*/
    fun onItemClickForDIY(entity: RecommendEntity, position: Int) {
        onClickChooseFunction?.invoke(entity, position)

    }

    private var onClickChooseFunction: ((entity: RecommendEntity, position: Int) -> Unit)? = null

    /**  点击item  **/
    /* @RepeatClick*/
    fun onItemClickChooseFunction(onClick: (entity: RecommendEntity, position: Int) -> Unit) {
        onClickChooseFunction = onClick
    }

    override fun convert(holder: BaseDataBindingHolder<ItemHomeFollowBinding>, item: RecommendEntity) {
        val binding =
            holder.dataBinding
        val variable = binding?.setVariable(BR.entity, item)
        binding?.setVariable(BR.adapter, this)
        binding?.setVariable(BR.position, holder.layoutPosition)
        binding?.tvRead?.setOnClickListener { setOnItemChildClick(it, holder.layoutPosition) }

        binding?.img?.setCircleCropImageUrl(item?.avatar)

        binding?.executePendingBindings()
    }
}